package com.cskaoyan.service.wxservice.impl;

import com.cskaoyan.bean.po.MarketOrderExample;
import com.cskaoyan.bean.chaosbean.user.vo.WxUserIndexVO;
import com.cskaoyan.bean.chaosbean.user.vo.WxUserOrderVO;
import com.cskaoyan.mapper.MarketOrderMapper;
import com.cskaoyan.service.wxservice.UserWeChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author 楚夏三分
 * @datetime 2023/1/3 7:26
 * @description: TODO:
 */
@Service
public class UserWechatServiceImpl implements UserWeChatService {
    @Autowired
    private MarketOrderMapper orderMapper;

    @Override
    public WxUserIndexVO userIndex() {
        Integer userId = 1;

        MarketOrderExample example1 = new MarketOrderExample();
        MarketOrderExample.Criteria criteria1 = example1.createCriteria();
        criteria1.andUserIdEqualTo(userId)
                .andOrderStatusEqualTo(new Short((short) 101))
                .andDeletedEqualTo(false);

        MarketOrderExample example2 = new MarketOrderExample();
        MarketOrderExample.Criteria criteria2 = example2.createCriteria();
        criteria2.andUserIdEqualTo(userId)
                .andOrderStatusEqualTo(new Short((short) 201))
                .andDeletedEqualTo(false);

        MarketOrderExample example3 = new MarketOrderExample();
        MarketOrderExample.Criteria criteria3 = example3.createCriteria();
        criteria3.andUserIdEqualTo(userId)
                .andOrderStatusEqualTo(new Short((short) 301))
                .andDeletedEqualTo(false);

        MarketOrderExample example4 = new MarketOrderExample();
        MarketOrderExample.Criteria criteria4 = example4.createCriteria();
        ArrayList<Short> receivedList = new ArrayList<>();
        receivedList.add((short) 401);
        receivedList.add((short) 402);
        criteria4.andUserIdEqualTo(userId)
                .andOrderStatusIn(receivedList)
                .andCommentsGreaterThan((short) 0)
                .andDeletedEqualTo(false);

        long unPaid = orderMapper.countByExample(example1);
        long paid = orderMapper.countByExample(example2);
        long sent = orderMapper.countByExample(example3);
        long received = orderMapper.countByExample(example4);

        WxUserOrderVO wxUserOrderVO = new WxUserOrderVO(received, unPaid, paid, sent);
        return new WxUserIndexVO(wxUserOrderVO);
    }
}
